package com.poker.controller;

import com.poker.entity.UserGame;
import com.poker.service.UserGameService;
import com.poker.util.Misc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @ClassName UserGameController
 * @Description TODO
 * @Author duyuanyuan
 * @Date 2019/3/18 15:38
 * @Version 1.0
 **/
@Controller
@RequestMapping("/userGame")
public class UserGameController extends BaseController {
    @Resource
    private UserGameService userGameService;

    @RequestMapping("/edit")
    public String edit(Model model, String userId, String activityId) {
          UserGame userGame = new UserGame();
          userGame.setActivityId(activityId);
          userGame.setUserId(userId);
          model.addAttribute("userGame", userGame);
          model.addAttribute("editType", "ADD");
          return managerPage("userGame/edit");
      }
    @ResponseBody
    @RequestMapping("/add")
    public String add(UserGame userGame) {
        if (Misc.isEmpty(userGame)) return toJson(false, "添加信息为空", null);
        userGameService.saveUserGame(userGame);
        return toJson(true, "success", null);
    }
}
